package com.example.grpcclient.Service;

import com.example.grpclib.GreeterGrpc;
import com.example.grpclib.HelloReply;
import com.example.grpclib.HelloRequest;
import io.grpc.Channel;
import net.devh.springboot.autoconfigure.grpc.client.GrpcClient;
import org.springframework.stereotype.Service;


/**
 * @Author 赵云龙
 * @Date 2020/6/20
 * @Description TODO
 */

@Service
public class HelloGrpcClientServerImpl {
   // gRPC server name
    @GrpcClient("grpc-server")
    private Channel channel;


    public String sendMessage(String name){
        GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel);
        HelloReply helloReply = stub.sayHello(HelloRequest.newBuilder().setName(name).build());
        return helloReply.getMessage();
    }

}
